<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>12336</title>
<%@ include file="/common/meta.jsp"%>
<%@ include file="/common/common.jsp"%>
 
</head>
<body>
	<div id="component_page_body">
		<s:if test="'rollannounce'==componentType">
			<%@ include file="rollannounce.jsp"%>
		</s:if>
		<s:elseif test="'rotate'==componentType">
			<%@ include file="rotate.jsp"%>
		</s:elseif>
		<s:elseif test="'association'==componentType">
			<%@ include file="associationdoc.jsp"%>
		</s:elseif>
		<s:elseif test="'pagination'==componentType">
			<%@ include file="pagination.jsp"%>
		</s:elseif>
		<s:elseif test="'site_cat_nav'==componentType">
			<%@ include file="sitecatnav.jsp"%>
		</s:elseif>
		<s:elseif test="'cateFrame'==componentType">
			<%@ include file="cateFrame.jsp"%>
		</s:elseif>
		<s:elseif test="'crumbs'==componentType">
			<%@ include file="crumbs.jsp" %>
		</s:elseif>
		<s:elseif test="'leftTree'==componentType">
			<%@ include file="lefttree.jsp" %>
		</s:elseif>
		<s:hidden name="componentType" id="hidden_component_type" />
	</div>
</body>
</html>

<script type="text/javascript">
	var label_id;
	 
	// 获取catIDs
 
	// 参数确认 
	$("#confirm_parameter").click(function(){
		loadCom();
		
	}); 
	
	function loadCom(){
		var paraArr = new Array();
		var parameters =getParameters(paraArr).join("@");
		var type = $(window.document).find("#hidden_component_type").val(); 
			window.parent.loadComponent(type,parameters);
	}
	// 参数重置
	$("#reset_parameter").click(function(){		 
		//input 重置
		$(window.document).find('input:text[class="template-arg"]').each(function(i,item){
			$(item).val('');
		});
		//树选择重置
		try {
			var treeObj = $.fn.zTree.getZTreeObj('cat_tree');
			var nodes = treeObj.getCheckedNodes(true);
			for(var i=0;i<nodes.length;i++){
				nodes[i].checked = false;
				treeObj.updateNode(nodes[i]);
			}
		} catch (e) {			 
		}
		
		window.parent.$("#component_code_div").html('');
	});

	// 获取参数 （包含catIDS）
	function getParameters(arr){
		$(window.document).find('input:text[class="template-arg"]').each(function(i,item){
			var v =$.trim($(item).val()); 
			var name = $.trim($(item).attr("name"));
			arr.push(name);
			if(v && v!=''){
				arr.push(v);
			}else{
				arr.push('-');
			} 
		});
		return arr;
	}
    $("#code_insert_btn").click(function(){
    	var insert =window.parent.$("#component_code_div").html();
	    	if(!insert){
	    		loadCom();
	    	}
			window.parent.finalf();
    });

</script>
<link href="${ctx}/css/zTreeStyle/zTreeStyle.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="${ctx}/js/jquery.ztree.core-3.0.js"></script>
<script type="text/javascript" src="${ctx}/js/jquery.ztree.excheck-3.0.js"></script>
<script type="text/javascript">
var setting_radio = {
		check: {
			enable: true,
			chkStyle: "radio",
			radioType: "all"
		},
		data: {
			simpleData: {
				enable: true
			}
		},
		callback: {
			onCheck: zTreeOnCheck
		}
	};
var setting_checkbox = {
		check: {
			enable: true,
			chkStyle: "checkbox",
			chkboxType :{Y:'s',N:'s'}
		},
		data: {
			simpleData: {
				enable: true
			}
		},
		callback: {
			onCheck: zTreeOnCheck
		}
	};	
 
function loadCatetree (type,needUrl,id,setting,isAllSite){	
	$.ajax({
		async:false, 
		url:"${ctx}/site/sitetree.action?t="+new Date().getTime(),
		data:{"type":type,"needurl":needUrl,"allSite":isAllSite},
		type:"post",
		dataType:"text",
		success:function(ss){
			var zNodes = eval('('+ss+')');
			$.fn.zTree.init($("#"+id), setting, zNodes);
			 
		}
	});
} 
function loadTopictree (id){	
	$.ajax({
		async:false, 
		url:"${ctx}/site/site-loadalltopic.action?t="+new Date().getTime(),
		data:{'allSite':false},		
		type:"post",
		dataType:"text",
		success:function(ss){
			var zNodes = eval('('+ss+')');
			setting_checkbox.callback.onCheck=zTreeOnChecktopic;
			$.fn.zTree.init($("#"+id), setting_checkbox, zNodes);
			 
		}
	});
}
function loadSitetree (id){	
	$.ajax({
		async:false, 
		url:"${ctx}/site/site-loadallsite.action?t="+new Date().getTime(),		 
		type:"post",
		dataType:"text",
		success:function(ss){
			var zNodes = eval('('+ss+')');
			setting_checkbox.callback.onCheck=zTreeOnChecksite;
			$.fn.zTree.init($("#"+id), setting_checkbox, zNodes);
			 
		}
	});
}
function zTreeOnCheck(){
	var treeObj = $.fn.zTree.getZTreeObj('cat_tree');
	var nodes = treeObj.getCheckedNodes(true);
	var array_z = new Array();
	if(nodes){
		for(var i=0; i<nodes.length;i++){
			array_z.push(nodes[i].id);
		}
		var ids_z = array_z.join(",");
		$("#component_page_parameter_cat_ids").val(ids_z);
	}
} 
function zTreeOnChecktopic(){
	var treeObj = $.fn.zTree.getZTreeObj('topic_tree');
	var nodes = treeObj.getCheckedNodes(true);
	var array_z = new Array();
	if(nodes){
		for(var i=0; i<nodes.length;i++){
			array_z.push(nodes[i].id);
		}
		var ids_z = array_z.join(",");
		$("#component_page_parameter_topic_ids").val(ids_z);
	}
}

function zTreeOnChecksite(){
	var treeObj = $.fn.zTree.getZTreeObj('site_tree');
	var nodes = treeObj.getCheckedNodes(true);
	var array_z = new Array();
	if(nodes){
		for(var i=0; i<nodes.length;i++){
			array_z.push(nodes[i].id);
		}
		var ids_z = array_z.join(",");
		$("#component_page_parameter_site_ids").val(ids_z);
	}
}
</script>